package com.sjsu.aws.rendavu;

/**
 * 
 * @author Shweta Dattatreya
 * 
 */
public class Master extends Thread {
	protected static final String ADDR = "192.168.1.100";
	protected static final String PORT = "6000";
	private String id;
	private AWSClient client;
	private boolean exit;
	private Watcher watcher;

	private class WatcherImpl implements Watcher {
		public void updated() {
		}

		public void deleted() {
			exit = true;
		}
	}

	/**
	 * 
	 * @param node
	 * @throws Exception
	 */
	public Master(String node) throws Exception {
		id = node;
		exit = false;
		watcher = new WatcherImpl();
		client = AWSClient.getInstance();

		synchronized (client) {
			client.updateAddress(id, ADDR, PORT);
			client.addWatcher(watcher);
		}
	}

	public void run() {
		try {
			while (!exit) {
				Thread.sleep(10 * 1000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("Master Exiting");
	}
}
